#include "sqlite3_test.h"

int printCallBack(void* pv, int argc, char** argv, char** col);
int insertSqlite(sqlite3* db);
int deleteSqlite(sqlite3 *db);
int updateSqlite(sqlite3 *db);
int querySqlite(sqlite3 *db);
int quitSqlite(sqlite3 *db);

int main()
{
    int insert;
    int ret;
    sqlite3 *db;
    char *errmsg;
    int id, score;
    char name[32];

    ret = sqlite3_open(PATH, &db);
    if (SQLITE_OK != ret)
    {
        printf("%s\n", sqlite3_errmsg(db));
    } else {
        printf("open sqlite success\n");
    }

    ret = sqlite3_exec(db, "create table if not exists stu (name char, id Integer, score Integer);", NULL, NULL, &errmsg);
    if (SQLITE_OK != ret)
    {
        printf("%s\n", errmsg);
    } else {
        printf("create sqlite table success\n");
    }

    while(1)
    {
        printf("************************************************************************\n");
        printf("1: insert\t 2: delete\t 3: update\t 4: query\t 5: quit\n");
        printf("************************************************************************\n");

        scanf("%d", &insert);
        getchar();

        switch (insert)
        {
            case 1:
                insertSqlite(db);
                break;
            case 2:
                deleteSqlite(db);
                break;
            case 3:
                updateSqlite(db);
                break;
            case 4:
                querySqlite(db);
                break;
            case 5:
                quitSqlite(db);
                break;        
            default:
                printf("insert error !\n");
                break;
        }
    }
    
    return 0;
}